package com.asm.DBloader;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class ASM_fReasonDS {
	
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;

	
	public ASM_fReasonDS (Context context)
	{
		this.context = context;
		dbHelper = new ASM_DB(context);
	}
	
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	
	public int Create(ASM_fReason det) {
		
		int count =0;
		
		if(dB == null){
			open();
		}else if(!dB.isOpen()){
			open();
		}
		
		ContentValues values = new ContentValues();
		values.put(ASM_DB.asmFreason_ReaCode,det.getAsmFreason_ReaCode());
		values.put(ASM_DB.asmFreason_ReaName,det.getAsmFreason_ReaName());
		values.put(ASM_DB.asmFreason_Type,det.getAsmFreason_Type());
		values.put(ASM_DB.asmFreason_ReaCode,det.getAsmFreason_ReaCode());
		values.put(ASM_DB.asmFreason_AddUser,det.getAsmFreason_AddUser());
		values.put(ASM_DB.asmFreason_AddDate,det.getAsmFreason_AddDate());
		values.put(ASM_DB.asmFreason_AddMach,det.getAsmFreason_AddMach());
		

		count = (int) dB.insert(ASM_DB.ASM_FREASON, null, values);

		dB.close();
		return count;
		
	}
	
	public ArrayList<String> getReason() 
	{
		if (dB == null) {
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		
		ArrayList<String> Details = new ArrayList<String>();
	
		String selectQuery = "select ReaName from fReason";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		while(cursor.moveToNext())
		{
		
			
			Details.add(cursor.getString(0));
			
			
			
		}
		
		return Details;
	}
}
